package com.java.zhuiyun.api.series_course.mapper;

import com.java.zhuiyun.api.back_course.model.BackCourseModel;
import com.java.zhuiyun.api.series_course.entity.SeriesCourse;
import com.java.zhuiyun.api.series_course.model.DictSeriesModel;
import com.java.zhuiyun.api.series_course.model.SeriesCourseModel;
import com.java.zhuiyun.api.sys_dict.entity.SysDict;
import com.java.zhuiyun.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ClassName SeriesCourseMapper
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/8/30 11:30
 **/
@Mapper
public interface SeriesCourseMapper extends BaseMapper<SeriesCourse> {
    @Select("select s.id,s.subject_image,s.subject_course_info,s.subject_course_title,s.subject_course_status,t.teacher_name " +
            "from series_course s,teacher t " +
            "where s.teacher_id=t.id and s.del_flag=0")
    List<SeriesCourseModel> selectSeries(SeriesCourseModel seriesCourseModel);

    @Select("select c.id,c.course_title,c.subject_id,d.dict_name from course c,sys_dict d where c.subject_id=d.id and c.teacher_id=#{teacherId} and c.del_flag=0 and c.course_status=0 and pay_type=1")
    List<BackCourseModel> selectBackCourse(Integer teacherId);

    @Select("select id,dict_name,prent_id from sys_dict where del_flag=0 and dict_type='subject'")
    List<DictSeriesModel> selectDict();

    @Select("select * from series_course where id=#{id} ")
    SeriesCourse selectCheck(Integer id);

    @Update("update series_course set course_ids=#{courseIds},update_time=#{updateTime} where id=#{id}")
    Integer addCourse(SeriesCourse s);

    @Select("select s.id,s.subject_image,s.subject_course_info,s.subject_course_title,s.subject_course_status,t.teacher_name " +
            "from series_course s,teacher t " +
            "where s.teacher_id=t.id and s.del_flag=0 and s.id=#{id}")
    SeriesCourseModel selectById(Integer id);

    @Update("update series_course set " +
            "subject_image=#{subjectImage},subject_course_info=#{subjectCourseInfo},subject_course_title=#{subjectCourseTitle},update_time=#{updateTime}" +
            "where id=#{id}")
    Integer updateSelective(SeriesCourse seriesCourse);

    @Update("update series_course set del_flag=1 where id=#{id}")
    Integer delCourse(Integer id);

    @Update("update series_course set subject_course_status=#{subjectCourseStatus},update_time=#{updateTime} where id=#{id}")
    Integer upSwitch(SeriesCourse seriesCourse);

    @Select("select s.id,s.subject_image,s.subject_course_info,s.subject_course_title,s.subject_course_status,t.teacher_name " +
            "from series_course s,teacher t " +
            "where s.teacher_id=t.id and s.del_flag=0 and t.user_id=#{id}")
    List<SeriesCourseModel> teacherSelectSeries(SeriesCourseModel seriesCourseModel);
}
